package org.ucas.kgraph.dto;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Defaults;
import org.springframework.http.HttpStatus;
import org.ucas.kgraph.entity.DocFile;
import org.ucas.kgraph.entity.Document;
import org.ucas.kgraph.entity.Term;
import org.ucas.kgraph.utils.exception.NotFoundException;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 词条的Dto对象
 * @author suemi
 */
public class DocumentDto  {

  public Long id;

  public String content;

  public List<DocFileDto> files;
  
  
  
  
  public List<DocFileDto> getFiles() {
	return files;
  }

  public void setFiles(List<DocFileDto> files) {
	this.files = files;
  }

  public Long getId() {
	return id;
  }

  public void setId(Long id) {
	this.id = id;
  }

  public String getContent() {
	return content;
  }

  public void setContent(String content) {
	this.content = content;
  }

  public static DocumentDto of(Document doc){
	    if(doc==null) throw NotFoundException.Term_NotExists;
	    DocumentDto docDto = new DocumentDto();
	    docDto.id = doc.getId();
	    docDto.content = doc.getContent();
	    docDto.setFiles(new ArrayList());
	    for (DocFile tmp : doc.getDocList()) {
	    	DocFileDto curr = new DocFileDto();
	    	curr.setId(tmp.getId().toString());
	    	curr.setName(tmp.getName());
	    	//System.out.println("id:"+curr.getId());
	    	//System.out.println("id:"+curr.getId());
	    	docDto.files.add(curr);
		}
	    return docDto;
	  }

  
}
